package cn.yunhe.servlet;

import cn.yunhe.bean.RoomType;
import cn.yunhe.bean.User;
import cn.yunhe.biz.RoomTypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/SimpleServlet")
public class SimpleServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        if (user == null) {
            resp.sendRedirect("userLogin.jsp");
            return;
        }
        String roomtype = req.getParameter("roomtype");
        int roomsize = Integer.parseInt(req.getParameter("roomsize"));
        String intime = req.getParameter("intime");
        String outtime = req.getParameter("outtime");
        RoomTypeService roomTypeService = new RoomTypeService();
        RoomType roomType = new RoomType(roomtype, roomsize, intime, outtime);
        int flag = roomTypeService.insertroom(roomType);
        if (flag > 0) {
            req.getRequestDispatcher("hotelcomment.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
